package org.example.tails.controller;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.tails.common.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class controllerCookie {
    @GetMapping("/c1")
    public int c1(HttpServletResponse response){
        response.addCookie(new Cookie("username","admin"));
        return 1;
    }

    @RequestMapping("/c2")
    public int c2(HttpServletRequest request){
        Cookie[] cookies= request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("username")){
                System.out.println(cookie.getName());
            }
        }
        return 1;
    }

}
